package niit.wei.servlet;

import niit.wei.entity.Book;
import niit.wei.service.BookService;
import niit.wei.service.impl.BookServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/UpdateBookServlet")
public class UpdateBookServlet extends HttpServlet {
    private BookService bookService =  new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Book book = new Book();
        String bookId = request.getParameter("bookId");
        book.setBookId(Integer.parseInt(bookId));
        String bookName = request.getParameter("bookName");
        book.setBookName(bookName);
        String authorName = request.getParameter("authorName");
        book.setAuthorName(authorName);
        String price = request.getParameter("price");
        book.setPrice(Double.parseDouble(price));
        System.out.println(price);
        String categoryId = request.getParameter("categoryId");
        System.out.println(categoryId);
        book.setCategoryId(Integer.parseInt(categoryId));
        bookService.updateBook(book);
        response.sendRedirect("book_list.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
